import { RECEIVE_SONGLIST, RECEIVE_NEW_MUSIC } from "./types";
import { createSong } from "../../../assets/js/songModel";
const defaultRecommend = {
  songList: [],
  newMusics: []
};
/** 这里如果使用Object.assign不会触发更新，Object.assign 对深层次对象只能时浅拷贝，如果只有一层就是深拷贝，这里返回的state必须时新对象 */
export default function recommend(state = defaultRecommend, action) {
  switch (action.type) {
    case RECEIVE_NEW_MUSIC:
      const list = action.data.map(song => {
        return createSong(song);
      });
      return {
        songList: [...state.songList],
        newMusics: list
      };
    case RECEIVE_SONGLIST:
      return {
        songList: action.data.slice(0, 6),
        newMusics: [...state.newMusics]
      };
    default:
      return state;
  }
}
